﻿#ifndef TETRISPIECE_H
#define TETRISPIECE_H

/**
 * @brief The TetrisPiece class 方块类：负责单个方块的形状，位置还有旋转逻辑
 */

#include <QPoint>
#include <QColor>
#include <QRandomGenerator>

class TetrisPiece
{
public:
    enum PieceShape{NoShape, ZShape, SShape, LineShape, TShape, SquareShape, LShape, MirroredLShape};

    TetrisPiece() {setShape(NoShape);}

    void setRandomShape();
    void setShape(PieceShape shape);

    PieceShape shape() const { return pieceShape; }
    // 第index个小方块的坐标（0-3）
    int x(int index) const { return coords[index].x(); }
    int y(int index) const { return coords[index].y(); }
    // 所有方块中的最大/小坐标
    int minX() const;
    int maxX() const;
    int minY() const;
    int maxY() const;

    TetrisPiece rotatedLeft() const;
    TetrisPiece rotatedRight() const;
    QColor color() const;

private:
    void setX(int index, int x) { coords[index].setX(x); }
    void setY(int index, int y) { coords[index].setY(y); }

    PieceShape pieceShape;
    QPoint coords[4];
};

#endif // TETRISPIECE_H
